//此地图绘画仅用于H5，可以参考PC端招聘模块中普工专区招聘详情页
const drawMap = {
	do: set => {
		let site_map = pageData.mapType; //地图类型
		drawMap[site_map](set); //绘画
	},
	baidu: ({
		boxId = 'map', //元素标签的id
		lng = pageData.lng || '',
		lat = pageData.lat || '',
		labelStr = '',
		labelSet = {},
		scale = 15,
		moveStart = res => {}, //拖拽地图开始
		moveEnd = res => {}, //拖拽地图结束
		zoomEnd = res => {}, //鼠标滚动缩放结束
	}) => { //百度
		let map = new BMap.Map(boxId); // 创建Map实例
		let point = new BMap.Point(lng, lat); // 创建点坐标 
		map.centerAndZoom(point, scale); // 初始化地图，设置中心点坐标和地图级别
		map.addEventListener('movestart', moveStart());
		map.addEventListener('moveend', moveEnd());
		map.addEventListener('zoomend', zoomEnd());
		// 自定义指示点标签样式（可以点和标签一起设置）
		let bLabel = new BMap.Label(
			labelStr, {
				position: point,
				offset: new BMap.Size(labelSet.x, labelSet.y) //中心点位置调整
			});
			bLabel.setStyle({
				border:'none',
				background:'none'
			})
		map.addOverlay(bLabel);
	},
	amap: ({
		boxId = 'map', //元素标签的id
		lng = pageData.lng || '',
		lat = pageData.lat || '',
		labelStr = '',
		scale = 14
	}) => { //高德
		let map = new AMap.Map(boxId, {
			viewMode: '2D', //默认使用 2D 模式
			zoom: scale, //地图级别
			center: [lng, lat], //地图中心点
		});

		// 构造点标记
		let marker = new AMap.Marker({
			content: labelStr,
			position: [+lng, +lat],
			map: map,
			draggable: false, //是否可拖拽
		});
		// map.setFitView(marker);
	},
	tmap: ({
		boxId = 'map', //元素标签的id
		lng = pageData.lng || '',
		lat = pageData.lat || '',
		labelStr = '',
		scale = 14
	}) => { //天地图
		let map = new T.Map(boxId, {
			projection: 'EPSG:4326'
		});
		let center = new T.LngLat(+lng, +lat);
		map.centerAndZoom(center, scale);
		var label = new T.Label({
			text: labelStr,
			position: center,
			// offset: new T.Point(-9, 0)
		});
		//创建地图文本对象
		map.addOverLay(label);
	},
	google: async ({
		boxId = 'map', //元素标签的id
		lng = pageData.lng || '',
		lat = pageData.lat || '',
		labelStr = '',
		scale = 14
	}) => { //谷歌
		const {
			Map
		} = await google.maps.importLibrary("maps");
		map = new Map(document.getElementById(boxId), {
			center: {
				lat: +lat,
				lng: +lng
			},
			zoom: scale,
			disableDefaultUI: true
		});
		var marker_posi = new google.maps.LatLng(Number(lat), Number(lng));
		var marker = new MarkerWithLabel({
			position: marker_posi,
			draggable: true,
			map: map,
			labelAnchor: new google.maps.Point(40, 50),
			labelContent: labelStr,
			// icon: '/static/images/blank.gif',
		});
	}
}
export default drawMap;